﻿using UnityEngine;
using System.Collections.Generic;

using KaoticSSB.GameModes;

namespace KaoticSSB.Menus
{
	public class OfflineModeSelectScreen : MonoBehaviour 
	{
		// Use this for initialization
		void Start () 
		{
			mGameModes = GameModeManager.SupportedGameModes;
		}
		
		// Update is called once per frame
		void Update () 
		{
			mInputHelper.Update();

			if(Input.GetButtonDown("Action_Button"))
			{
				StartGame ();
			}
		}
		
		public void OnGUI()
		{
			GUILayout.BeginHorizontal();
			GUILayout.Space (10);
			GUILayout.BeginVertical ();
			GUILayout.Space (10);

			GUILayout.BeginHorizontal();
			GUILayout.Label ("Game mode: ");

			InputHelper.DirectionsHeld direction = mInputHelper.GetLeftJoystickDown(1);
			if(GUILayout.Button ("<") || direction.Left)
			{
				mSelectedGameModeIndex--;
				if(mSelectedGameModeIndex < 0)
				{
					mSelectedGameModeIndex = mGameModes.Length-1;
				}
			}
			GUILayout.Label (mGameModes[mSelectedGameModeIndex]);
			if(GUILayout.Button (">") || direction.Right)
			{
				mSelectedGameModeIndex++;
				mSelectedGameModeIndex = mSelectedGameModeIndex % mGameModes.Length;
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal();
			GUILayoutOption[] options = { GUILayout.Width(60), GUILayout.Height (35) };
			if(GUILayout.Button ("Back", options))
			{
				Application.LoadLevel ("TitleScene");
			}
			GUILayoutOption[] startOptions = { GUILayout.Width(90), GUILayout.Height (35) };
			if(GUILayout.Button ("Start Game", startOptions))
			{
				StartGame ();
			}
			GUILayout.EndHorizontal();

			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
		}

		private string[] mGameModes;		
		private int mSelectedGameModeIndex = 0;
		private InputHelper mInputHelper = new InputHelper();

		private void StartGame()
		{
			GameModeManager.SelectedGameType = mGameModes[mSelectedGameModeIndex];
			Application.LoadLevel ("BattleStage");
		}

	}
}